package com.rainng.coursesystem.manager.leader;

import com.rainng.coursesystem.dao.EventDAO;
import com.rainng.coursesystem.dao.MemberEventDAO;
import com.rainng.coursesystem.manager.BaseManager;
import com.rainng.coursesystem.model.entity.EventEntity;
import com.rainng.coursesystem.model.entity.MemberEventEntity;
import com.rainng.coursesystem.model.vo.response.table.LeaderBudgetItemVO;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class BudgetManager extends BaseManager {
    private final EventDAO eventDAO;
    private final MemberEventDAO memberEventDAO;

    public BudgetManager(EventDAO eventDAO, MemberEventDAO memberEventDAO) {
        this.eventDAO = eventDAO;
        this.memberEventDAO = memberEventDAO;
    }

    public Integer getLeaderBudgetPageCount(Integer leaderId, String eventName, String memberName) {
        return calcPageCount(
                memberEventDAO.countLeaderBudget(leaderId, eventName, memberName),
                MemberEventDAO.PAGE_SIZE);
    }

    public List<LeaderBudgetItemVO> getLeaderBudgetPage(Integer index, Integer leaderId, String eventName, String memberName) {
        return memberEventDAO.getLeaderBudgetPage(index, leaderId, eventName, memberName);
    }

    public MemberEventEntity getMemberEventById(Integer memberEventId) {
        return memberEventDAO.get(memberEventId);
    }

    public EventEntity getEventById(Integer eventId) {
        return eventDAO.get(eventId);
    }


    public int updateMemberEvent(MemberEventEntity entity) {
        return memberEventDAO.update(entity);
    }
}
